package com.itheima.thread.blockingqueue.demo02;

import java.util.concurrent.ArrayBlockingQueue;

// 消费者线程的任务类，这个类的主要作用就是从阻塞队列中获取box进行消费
public class CustomerThread implements Runnable {

    private ArrayBlockingQueue<Box> arrayBlockingQueue ;
    public CustomerThread(ArrayBlockingQueue<Box> arrayBlockingQueue) {            // 作用：用来接收阻塞队列
        this.arrayBlockingQueue = arrayBlockingQueue ;
    }

    @Override
    public void run() {

        while(true) {       // 表示需要不断进行消费
            try {
                Box box = arrayBlockingQueue.take();
                System.out.println(box.getMilkType() + "------------" + box.getAmount() );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}
